package NetWork;

import java.util.Queue;
import java.util.Vector;

import Global.TransObject;

class DelegateThreadStr extends Thread
{
	NetWorkDelegate	delegate;
	String			hostString;
	String			string;
	int				portNum;

	public DelegateThreadStr(NetWorkDelegate d, String host, int port, String str)
	{
		delegate = d;
		hostString = host;
		portNum = port;
		string = str;
	}

	public void run()
	{
		//delegate.didReceiveString(hostString, portNum, string);
	}
}

public class StringScheduler extends Thread
{
	public Queue<TransObject>	transObjectQueue;
	public String				hostsString;
	public int					portNum;
	protected boolean			keepAlive;

	public StringScheduler(String host, int port,Queue<TransObject> queue)
	{
		transObjectQueue = queue;
		hostsString = host;
		portNum = port;
		keepAlive = true;
	}

	public void stopThread()
	{
		keepAlive = false;
	}

	public void run()
	{
		while (keepAlive)
		{
			TransObject transObject = transObjectQueue.poll();
			if (transObject != null)
			{
				Vector<NetWorkDelegate> vector = TransmissionUtil.delegateVector;
				for (NetWorkDelegate d : vector)
				{
					d.didReceiveString(transObject.siteType,hostsString, portNum, (String)transObject.obj);
				}
			}
			else
			{
				try
				{
					sleep(100);
				}
				catch (InterruptedException e)
				{
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
}
